package gam.t1.appraisal2;

import gam.t1.appraisal2.dinv.DataInventory;
import gam.t1.appraisal2.dinv.impl.AppraisalDataInventory;
import gam.t1.appraisal2.reninv.RenderInventory;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class AppraisalCommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equals("appraisal")){
            if (args.length >= 1){
                String prefix = args[0];
                switch (prefix){
                    case "open":
                        if (sender instanceof Player){
                            Player p = (Player) sender;
                            if (args.length > 1){
                                String argument = args[1];
                                DataInventory var1 = Data.getAppraisalDataInventory(p.getUniqueId());
                                if (var1 == null){
                                    AppraisalDataInventory var2 = Data.APPRAISAL_DATA_INVENTORIES.get(argument);
                                    if (var2 != null) {
                                        var1 = var2.clone();
                                    } else {
                                        p.sendMessage("Cannot find the AppraisalInventoryStorage in memory.");
                                        break;
                                    }
                                    Data.addAppraisalDataInventory(p.getUniqueId(),var1);
                                }
                                RenderInventory.render(var1.getItems(),p);
                            } else {
                                p.sendMessage("Error Command.pls use /appraisal open [name]");
                            }
                        } else Bukkit.getLogger().info("The command is running allowed by player.");
                        break;
                    case "reload":
                        DIConfig.loadAll();
                        sender.sendMessage("Successful reload!");
                        break;
                }
            }
        }
        return false;
    }
}
